﻿using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel;

namespace Songhay.Composition.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class CompositionTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #region Engine parts

        interface IRule { }

        [Export(typeof(IRule))]
        class Rule1 : IRule { }

        [Export(typeof(IRule))]
        class Rule2 : IRule { }

        class Engine
        {
            public Engine()
            {
            }

            [ImportMany(typeof(IRule))]
            public IEnumerable<IRule> Rules { get; set; }
        }

        #endregion

        [TestMethod]
        public void EngineShouldHaveRules()
        {
            var e = new Engine();

            var catalog = CompositionUtility.GetAssemblyCatalog(typeof(CompositionTest).Assembly);
            using(var container = new CompositionContainer(catalog))
            {
                container.ComposeParts(e);
            }

            Assert.IsNotNull(e.Rules);
        }
    }
}
